package Service.Impl;

import Bean.Cart;

import Dao.CartDao;
import Dao.Impl.CartDaoImpl;
import Dao.Impl.FurnDaoImpl;
import Service.CartService;

import java.util.ArrayList;
import java.util.List;

public class CartServiceImpl implements CartService {

    public static void main(String[] args) {
        CartServiceImpl cartService = new CartServiceImpl();
       //cartService.addCartFurn(1,1);
        System.out.println(cartService.deleteCartFurn(1,1));

    }
    private CartDao cartDao = new CartDaoImpl();
    @Override
    public void addCartFurn(Integer UserID, Integer FurnId) {
        cartDao.InsertCart(UserID,FurnId);
    }

    @Override
    public List<Cart.CartGood> getAllCartFurn(Integer UserID) {
        List<Cart.CartGood> list = new ArrayList<>();
        return cartDao.getAllCartFurn(UserID,Cart.CartGood.class);
    }

    @Override
    public boolean isCartFurn(Integer UserId, Integer FurnId, Class aClass) {
        Object cartFurn = cartDao.isCartFurn(UserId, FurnId, aClass);
        if (cartFurn == null){
            return false;
        }
        return true;
    }

    @Override
    public boolean deleteCartFurn(Integer UserId, Integer FurnId) {
        return cartDao.deleterSomeCart(UserId,FurnId);
    }

    @Override
    public void deleteCartFurn(Integer UserId) {
        cartDao.deterAllCart(UserId);
    }

    @Override
    public void SetCartSize(Integer UserID, Integer FurnID, Integer Size) {
        cartDao.SetCartSize(UserID, FurnID, Size);
    }

    @Override
    public Integer CartIdNumber(Integer userId) {
        String sql ="select count(*) from CartFurn where UserId = ?;";
        FurnDaoImpl furnDao = new FurnDaoImpl();
        return furnDao.getCount(sql,userId);
    }
}
